package com.example.qiaoruian.shequ.adapter;

import android.content.Context;
import android.graphics.Color;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.TextView;

import com.example.qiaoruian.shequ.R;
import com.example.qiaoruian.shequ.bean.UserBean;

import java.util.List;


public class ListViewAdapter extends BaseAdapter {
    private List<UserBean> list;
    private Context context;
    private LayoutInflater inflater;

    public ListViewAdapter(List<UserBean> list, Context context) {
        this.list = list;
        this.context = context;
        inflater = LayoutInflater.from(context);
    }

    @Override
    public int getCount() {
        return list.size();
    }

    @Override
    public UserBean getItem(int position) {
        return list.get(position);
    }

    @Override
    public long getItemId(int position) {
        return position;
    }

    @Override
    public View getView(int position, View convertView, ViewGroup parent) {
        ViewHolder holder = new ViewHolder();
        if (convertView == null) {
            convertView = inflater.inflate(R.layout.listadapter_activity, null);
            holder.tv_title = (TextView) convertView.findViewById(R.id.tv_title);
            holder.tv_content = (TextView) convertView.findViewById(R.id.tv_content);
            convertView.setTag(holder);
        }
        holder = (ViewHolder) convertView.getTag();
        UserBean user = list.get(position);
        int color = 0;
        if (user.getType() == 1) {
            color = Color.parseColor("#F93D3C");
        }
        if (user.getType() == 2) {
            color = Color.parseColor("#F9A751");
        }
        holder.tv_title.setTextColor(color);
        holder.tv_title.setText(user.getTitle());
        holder.tv_content.setText(user.getContent());
        return convertView;
    }

    private class ViewHolder {

        private TextView tv_title;
        private TextView tv_content;
    }
}
